import Model from "./Model";
import Config from "./Config";

const { ccclass, property } = cc._decorator;
@ccclass
export default class TopUI extends cc.Component {

    @property(cc.Label)
    label_level: cc.Label = null;

    @property
    text: string = 'hello';

    onLoad() {

        if (Model.game.selectedModel == 1)
            this.label_level.getComponent(cc.Label).string = Model.game.selectedLevel + '/' + (Config.preciseLevels.length - 1)
        else if (Model.game.selectedModel == 2)
            this.label_level.getComponent(cc.Label).string = Model.game.selectedLevel + '/' + (Config.brickLevels.length - 1)
        else if (Model.game.selectedModel == 3)
            this.label_level.getComponent(cc.Label).string = Model.game.selectedLevel + '/' + (Config.dragLevels.length - 1)
        else if (Model.game.selectedModel == 4)
            this.label_level.getComponent(cc.Label).string = '第' + Model.game.selectedLevel + '关'

        if (Model.game.selectedModel != 4) {
            this.node.getChildByName('img_money').active = false;
            this.node.getChildByName('star_txt').active = false;
            // this.node.getChildByName('level_txt').active=false;
            this.node.getChildByName('btn_retry').active = true;

        }

        //动态调整top位置
        var size = cc.view.getVisibleSize();
        if (size.height / size.width > 2) {
            this.node.getComponent(cc.Widget).top = 115
        } else {
            this.node.getComponent(cc.Widget).top = 60
        }
    }

    start() {

        var star = 0
        for (var i = 0; i < Model.game.drawLevelInfo.length; i++) {
            if (Model.game.drawLevelInfo[i] > 0)
                star += Model.game.drawLevelInfo[i];
        }
        this.node.getChildByName('star_txt').getComponent(cc.Label).string = star + '/' + (Config.drawLevels.length - 1) * 3;

    }
    onBackClick() {


        cc.director.loadScene('menu')

    }
    onReplayClick() {
        if (Model.game.selectedModel == 1)
            cc.director.loadScene('game')
        else if (Model.game.selectedModel == 2)
            cc.director.loadScene('gameDrop')
        else if (Model.game.selectedModel == 3)
            cc.director.loadScene('gameDrag')
        else if (Model.game.selectedModel == 4)
            cc.director.loadScene('gameDraw')
    }
    onRankClick() {

    }
}
